package top.codechap.transaction;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author CodeChap
 * @date 2021-06-23 22:03
 * @description UserService
 */
@Service
public class UserService {

    @Autowired
    private UserDao userDao;

    @Transactional
    public void insertUser() {
        userDao.insert();
        System.out.println("插入完成...");
        int i = 10/0;   //此时会抛出异常,插入数据出现问题,数据应该回滚至插入之前的状态
    }
}
